#include "Util/LoggerManager.h"

// declare static members
LoggerManager LoggerManager::m_Instance;

LoggerManager::LoggerManager() {
}

LoggerManager::~LoggerManager() {
    LoggerMap::const_iterator it = m_LoggerMap.begin();
    for (; it != m_LoggerMap.end(); it++) {
        SAFE_DELETE(it->second);
    }
    m_LoggerMap.clear();
}

LoggerManager& LoggerManager::GetInstance() {
    return m_Instance;
}

Logger& LoggerManager::GetLogger(const char* log) {
    LoggerMap::const_iterator it = m_LoggerMap.find(log);
    if (it == m_LoggerMap::end()) {
        std::pair<LoggerMap::iterator,bool> result = m_LoggerMap.insert(
                std::make_pair(log, new Logger(log)));
        if (result.second) {
            it = result.first;
        }
    }
    return *it->second;
}